var MovieSession = {
	
	movieId : null,
	
	action : null,

	loadAllSessions : function(ajax_request){
		var data = eval("(" + ajax_request.responseText + ")");
		for(var i=0;i<data.sessions.length;i++) {
			if(MovieSession.action == "book") {
				var bookSessionItem = {
					movieName:data.sessions[i].movieName,
					sessionName:data.sessions[i].sessionName,
					hallName:data.sessions[i].hallName,
					price:data.sessions[i].price,
					bookOnLine:data.sessions[i].bookOnLine
				}; 
				sessionStore.newItem(bookSessionItem);
			}
			else if(MovieSession.action == "manage") {
				var manageSessionItem = {
					movieName:data.sessions[i].movieName,
					sessionName:data.sessions[i].sessionName,
					hallName:data.sessions[i].hallName,
					price:data.sessions[i].price,
					editSes:data.sessions[i].editSes,
					deleteSes:data.sessions[i].deleteSes
				}; 
				manageSessionStore.newItem(manageSessionItem);
			}
			
		}
//		dijit.byId("loadDiv").hide();
	},
	
	loadMovieBriefInfo : function(ajax_request) {
		var data = eval("(" + ajax_request.responseText + ")");
		
		var _mrName = document.getElementById("mrName");
		var _mrLanguage = document.getElementById("mrLanguage");
		var _mrTime = document.getElementById("mrTime");
		var _mrPhoto = document.getElementById("mrPhoto");
		
		_mrName.innerHTML = data.movieBriefInfo[0].mrName;
		_mrLanguage.innerHTML = data.movieBriefInfo[0].mrLanguage;
		_mrTime.innerHTML = data.movieBriefInfo[0].mrTime;
		_mrPhoto.src = data.movieBriefInfo[0].mrPhoto;
	},
	
	updateHallsInfo : function(ajax_request) {
		var data = eval("(" +ajax_request.responseText + ")");
		
		for(var i=0;i<data.halls.length;i++) {
			var item = {
				id_seat:data.halls[i].hallId + "_" + data.halls[i].hallSeats,
				name:data.halls[i].hallName
			}
			
			hallNameStore.newItem(item);
		}
	},
	
	askForMovieSessionInfo : function() {
		var href = "getMovieSessions.do?movieId="+this.movieId+"&action="+this.action;
		ajaxRequest(href, this.loadAllSessions, null);
	},
	
	askForMovieBriefInfo : function() {
		var href = "getMovieBriefInfo.do?movieId="+this.movieId;
		ajaxRequest(href, this.loadMovieBriefInfo, null);
	},
	
	init : function() {
		var href = "getHalls.do";
		ajaxRequest(href, this.updateHallsInfo, null);
	},
	
	setHallNote : function() {
		var hallCon = dijit.byId("hallContainer");
		var id_seat = hallCon.item['id_seat'];
		var hallNotedEle = document.getElementById("hallNote");
		var hallIdEle = document.getElementById("hallId");
		
		var hallId = id_seat[0].substring(0, id_seat[0].indexOf('_'));
		var seatNum = id_seat[0].substring(id_seat[0].indexOf('_')+1);
		
		hallNotedEle.innerHTML = "该放映厅拥有<span style='color:red'>" + seatNum + "</span>个座位"
		hallIdEle.value = hallId;
	}
};
